/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jlxy.ise.eroad.controller;

import com.google.gson.Gson;
import jlxy.ise.eroad.service.FreightService;
import jlxy.ise.eroad.service.Sret;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author shao
 */
@RestController
@EnableAutoConfiguration
public class FreightController {
    private static Logger log=Logger.getLogger(FreightController.class);

    @Autowired
    private FreightService us;
    
//    //添加管理员
//    @RequestMapping("/admin/add")
//    public String do_addAdmin(@RequestParam("username") String username, @RequestParam("passwd") String passwd, @RequestParam("power") String power) {
//        Sret sr = us.addAdmin(username, passwd, power);
//        return sret2json(sr);
//    }
//
//    //列出所有管理员
//    @RequestMapping("/admin/list")
//    public String do_listAdmin() {
//        Sret sr = us.listAdmin();
//        log.debug("/admin/list, success");
//        return sret2json(sr);
//    }
//    
//    //搜索管理员
//    @RequestMapping("/admin/search")
//    public String do_searchAdmin(@RequestParam("username") String username) {
//        Sret sr = us.searchAdmin(username);
//        log.debug("/admin/search, success");
//        return sret2json(sr);
//    }
//    
//    //修改管理员信息
//    @RequestMapping("/admin/alter")
//    public String do_alterAdmin(@RequestParam("username") String username, @RequestParam("id") String id) {
//        Sret sr = us.alterAdmin(username, id);
//        return sret2json(sr);
//    }
//    
//    //删除管理员
//    @RequestMapping("/admin/remove")
//    public String do_removeAdmin(@RequestParam("id") String id) {
//        Sret sr = us.removeAdmin(id);
//        return sret2json(sr);
//    }
    
    //列出所有司机
    @RequestMapping("/register/list")
    public String do_listDriver() {
        Sret sr = us.listDriver();
        log.debug("/register/list, success");
        return sret2json(sr);
    }
    
    //搜索手机号，查询司机id
    @RequestMapping("/register/search")
    public String do_searchPhone(@RequestParam("telephone") String telephone) {
        Sret sr = us.searchPhone(telephone);
        log.debug("/register/search, success");
        return sret2json(sr);
    }

    //注册页面，添加司机
    @RequestMapping("/register/add1")
    public String do_addDriver(@RequestParam("telephone") String telephone, @RequestParam("passwd") String passwd, @RequestParam("registertime") String registertime) {
        Sret sr = us.addDriver(telephone, passwd, registertime);
        log.debug("/register/add1, success");
        return sret2json(sr);
    }
    
    //司机信息页面，添加司机信息1
    @RequestMapping("/register/add2")
    public String do_addDriver1(@RequestParam("name") String name, @RequestParam("drivingnumber") String drivingnumber, @RequestParam("emergencyperson") String emergencyperson, @RequestParam("emergencynumber") String emergencynumber, @RequestParam("id") String id) {
        Sret sr = us.addDriver1(name, drivingnumber, emergencyperson, emergencynumber, id);
        log.debug("/register/add2, success");
        return sret2json(sr);
    }
    
    //车辆信息页面，添加司机信息2
    @RequestMapping("/register/add3")
    public String do_addDriver2(@RequestParam("username") String username, @RequestParam("operationnumber") String operationnumber, @RequestParam("vin") String vin, @RequestParam("enginenumber") String enginenumber, @RequestParam("brandmodel") String brandmodel, @RequestParam("type") String type, @RequestParam("length") String length, @RequestParam("width") String width, @RequestParam("height") String height, @RequestParam("capacity") String capacity, @RequestParam("isowner") String isowner, @RequestParam("description") String description, @RequestParam("id") String id) {
        Sret sr = us.addDriver2(username, operationnumber, vin, enginenumber, brandmodel, type, length, width, height, capacity, isowner, description, id);
        log.debug("/register/add3, success");
        return sret2json(sr);
    }
    
    //照片信息页面，添加司机信息3
    @RequestMapping("/register/add4")
    public String do_addDriver3(@RequestParam("drivinglicense") String drivinglicense, @RequestParam("operationlicense") String operationlicense, @RequestParam("travellicense") String travellicense, @RequestParam("vehiclephoto") String vehiclephoto, @RequestParam("id") String id) {
        Sret sr = us.addDriver3(drivinglicense, operationlicense, travellicense, vehiclephoto, id);
        log.debug("/register/add4, success");
        return sret2json(sr);
    }
    
    //登录验证
    @RequestMapping("/login/verify")
    public String do_loginVerify(@RequestParam("telephone") String telephone, @RequestParam("passwd") String passwd) {
        Sret sr = us.loginVerify(telephone, passwd);
        log.debug("/login/verify, success");
        return sret2json(sr);
    }
    
    //登录时修改登录时间和账号状态
    @RequestMapping("/login/alter")
    public String do_loginAlter(@RequestParam("lastlogintime") String lastlogintime, @RequestParam("status") String status, @RequestParam("id") String id) {
        Sret sr = us.loginAlter(lastlogintime, status, id);
        log.debug("/login/alter, success");
        return sret2json(sr);
    }
    
    //注销时修改账号状态
    @RequestMapping("/exit/alter")
    public String do_exitAlter(@RequestParam("status") String status, @RequestParam("id") String id) {
        Sret sr = us.exitAlter(status, id);
        log.debug("/exit/alter, success");
        return sret2json(sr);
    }
    
    //忘记密码验证
    @RequestMapping("/forget/verify")
    public String do_forgetVerify(@RequestParam("telephone") String telephone, @RequestParam("drivingnumber") String drivingnumber) {
        Sret sr = us.forgetVerify(telephone, drivingnumber);
        log.debug("/forget/verify, success");
        return sret2json(sr);
    }
    
    //重置密码
    @RequestMapping("/reset/verify")
    public String do_resetPasswd(@RequestParam("passwd") String passwd, @RequestParam("id") String id) {
        Sret sr = us.resetPasswd(passwd, id);
        log.debug("/reset/verify, success");
        return sret2json(sr);
    }
    
    //查看个人资料
    @RequestMapping("/my/info")
    public String do_listInfo(@RequestParam("id") String id) {
        Sret sr = us.listInfo(id);
        log.debug("/my/info, success");
        return sret2json(sr);
    }
    
     //修改个人资料
    @RequestMapping("/my/alter")
    public String do_alterInfo(@RequestParam("name") String name, @RequestParam("drivingnumber") String drivingnumber, @RequestParam("emergencyperson") String emergencyperson, @RequestParam("emergencynumber") String emergencynumber, @RequestParam("username") String username, @RequestParam("operationnumber") String operationnumber, @RequestParam("vin") String vin, @RequestParam("enginenumber") String enginenumber, @RequestParam("brandmodel") String brandmodel, @RequestParam("type") String type, @RequestParam("length") String length, @RequestParam("width") String width, @RequestParam("height") String height, @RequestParam("capacity") String capacity, @RequestParam("isowner") String isowner, @RequestParam("description") String description, @RequestParam("drivinglicense") String drivinglicense, @RequestParam("operationlicense") String operationlicense, @RequestParam("travellicense") String travellicense, @RequestParam("vehiclephoto") String vehiclephoto, @RequestParam("id") String id) {
        Sret sr = us.alterInfo(name, drivingnumber, emergencyperson, emergencynumber, username, operationnumber, vin, enginenumber, brandmodel, type, length, width, height, capacity, isowner, description, drivinglicense, operationlicense, travellicense, vehiclephoto, id);      
        log.debug("/my/alter, success");
        return sret2json(sr);
    }
    
//    //搜索意见
//    @RequestMapping("/feedback/search")
//    public String do_searchFeedback(@RequestParam("uid") String uid) {
//        Sret sr = us.searchFeedback(uid);
//        log.debug("/feedback/search, success");
//        return sret2json(sr);
//    }
//    
//    //添加意见
//    @RequestMapping("/feedback/add")
//    public String do_addFeedback(@RequestParam("content") String content, @RequestParam("time") String time, @RequestParam("uid") String uid) {
//        Sret sr = us.addFeedback(content, time, uid);
//        return sret2json(sr);
//    }
    
    //修改车辆状态
    @RequestMapping("/state/alter")
    public String do_alterState(@RequestParam("state") String state, @RequestParam("id") String id) {
        Sret sr = us.alterState(state, id);
        log.debug("/state/alter, success");
        return sret2json(sr);
    }
    
    //根据uid列出该司机所有感兴趣的城市
    @RequestMapping("/interest/list")
    public String do_listInterest(@RequestParam("uid") String uid) {
        Sret sr = us.listInterest(uid);
        log.debug("/interest/list, success");
        return sret2json(sr);
    }
    
    //列出省名
    @RequestMapping("/province/list")
    public String do_listProvince() {
        Sret sr = us.listProvince();
        log.debug("/province/list, success");
        return sret2json(sr);
    }
    
    //根据id查询对应的省名
    @RequestMapping("/province/query")
    public String do_queryPname(@RequestParam("id") String id) {
        Sret sr = us.queryPname(id);
        log.debug("/province/query, success");
        return sret2json(sr);
    }
    
    //列出城市名
    @RequestMapping("/city/list")
    public String do_listCity() {
        Sret sr = us.listCity();
        log.debug("/city/list, success");
        return sret2json(sr);
    }
    
    //根据pid列出与该省对应的所有城市
    @RequestMapping("/city/search")
    public String do_searchCity(@RequestParam("pid") String pid) {
        Sret sr = us.searchCity(pid);
        log.debug("/city/search, success");
        return sret2json(sr);
    }
    
    //根据id查询对应的城市名
    @RequestMapping("/city/query")
    public String do_queryCname(@RequestParam("id") String id) {
        Sret sr = us.queryCname(id);
        log.debug("/city/query, success");
        return sret2json(sr);
    }
    
    //添加感兴趣的城市
    @RequestMapping("/interest/add")
    public String do_addInterest(@RequestParam("pname") String pname, @RequestParam("cname") String cname, @RequestParam("uid") String uid) {
        Sret sr = us.addInterest(pname, cname, uid);
        log.debug("/interest/add, success");
        return sret2json(sr);
    }
    
    //根据cname和uid判断该城市是否已添加
    @RequestMapping("/interest/search")
    public String do_searchInterest(@RequestParam("cname") String cname, @RequestParam("uid") String uid) {
        Sret sr = us.searchInterest(cname, uid);
        log.debug("/interest/search, success");
        return sret2json(sr);
    }
    
    //删除感兴趣的城市
    @RequestMapping("/interest/remove")
    public String do_removeInterest(@RequestParam("id") String id) {
        Sret sr = us.removeInterest(id);
        log.debug("/interest/remove, success");
        return sret2json(sr);
    }
    
    //列出区名
    @RequestMapping("/district/list")
    public String do_listDistrict() {
        Sret sr = us.listDistrict();
        log.debug("/district/list, success");
        return sret2json(sr);
    }
    
    //根据cid列出与该城市对应的所有区县
    @RequestMapping("/district/search")
    public String do_searchDistrict(@RequestParam("cid") String cid) {
        Sret sr = us.searchDistrict(cid);
        log.debug("/district/search, success");
        return sret2json(sr);
    }
    
    //根据id查询对应的区名
    @RequestMapping("/district/query")
    public String do_queryDname(@RequestParam("id") String id) {
        Sret sr = us.queryDname(id);
        log.debug("/district/query, success");
        return sret2json(sr);
    }
    
    //筛选发货省
    @RequestMapping("/saddress/filter1")
    public String do_filterSaddress1(@RequestParam("sprovince") String sprovince, @RequestParam("flag") String flag) {
        Sret sr = us.filterSaddress1(sprovince, flag);
        log.debug("/saddress/filter1, success");
        return sret2json(sr);
    }
    
    //筛选发货省、市
    @RequestMapping("/saddress/filter2")
    public String do_filterSaddress2(@RequestParam("sprovince") String sprovince, @RequestParam("scity") String scity, @RequestParam("flag") String flag) {
        Sret sr = us.filterSaddress2(sprovince, scity, flag);
        log.debug("/saddress/filter2, success");
        return sret2json(sr);
    }
    
    //筛选发货省、市、区
    @RequestMapping("/saddress/filter3")
    public String do_filterSaddress3(@RequestParam("sprovince") String sprovince, @RequestParam("scity") String scity, @RequestParam("sdistrict") String sdistrict, @RequestParam("flag") String flag) {
        Sret sr = us.filterSaddress3(sprovince, scity, sdistrict, flag);
        log.debug("/saddress/filter3, success");
        return sret2json(sr);
    }
    
    //筛选收货省
    @RequestMapping("/eaddress/filter1")
    public String do_filterEaddress1(@RequestParam("eprovince") String eprovince, @RequestParam("flag") String flag) {
        Sret sr = us.filterEaddress1(eprovince, flag);
        log.debug("/eaddress/filter1, success");
        return sret2json(sr);
    }
    
    //筛选收货省、市
    @RequestMapping("/eaddress/filter2")
    public String do_filterEaddress2(@RequestParam("eprovince") String eprovince, @RequestParam("ecity") String ecity, @RequestParam("flag") String flag) {
        Sret sr = us.filterEaddress2(eprovince, ecity, flag);
        log.debug("/eaddress/filter2, success");
        return sret2json(sr);
    }
    
    //筛选收货省、市、区
    @RequestMapping("/eaddress/filter3")
    public String do_filterEaddress3(@RequestParam("eprovince") String eprovince, @RequestParam("ecity") String ecity, @RequestParam("edistrict") String edistrict, @RequestParam("flag") String flag) {
        Sret sr = us.filterEaddress3(eprovince, ecity, edistrict, flag);
        log.debug("/eaddress/filter3, success");
        return sret2json(sr);
    }
    
    //列出竞价中的所有订单
    @RequestMapping("/package/list")
    public String do_listPackage() {
        Sret sr = us.listPackage();
        log.debug("/package/list, success");
        return sret2json(sr);
    }
    
    //根据id查询订单的详细信息
    @RequestMapping("/package/search")
    public String do_searchPackage(@RequestParam("id") String id) {
        Sret sr = us.searchPackage(id);
        log.debug("/package/search, success");
        return sret2json(sr);
    }
    
    //订单报价，添加竞价用户和报价
    @RequestMapping("/bidding/add")
    public String do_addBidding(@RequestParam("uid") String uid, @RequestParam("price") String price, @RequestParam("uname") String uname, @RequestParam("pid") String pid) {
        Sret sr = us.addBidding(uid, price, uname, pid);
        log.debug("/bidding/add, success");
        return sret2json(sr);
    }
    
    //取消报价
    @RequestMapping("/bidding/remove")
    public String do_removeBidding(@RequestParam("uid") String uid, @RequestParam("pid") String pid) {
        Sret sr = us.removeBidding(uid, pid);
        log.debug("/bidding/remove, success");
        return sret2json(sr);
    }
    
    //判断用户是否参与该订单的竞价
    @RequestMapping("/bidding/search")
    public String do_searchBidding(@RequestParam("uid") String uid, @RequestParam("pid") String pid) {
        Sret sr = us.searchBidding(uid, pid);
        log.debug("/bidding/search, success");
        return sret2json(sr);
    }
    
    //定时上报位置
    @RequestMapping("/location/add")
    public String do_addLocation(@RequestParam("lon") String lon, @RequestParam("lat") String lat, @RequestParam("timestamp") String timestamp, @RequestParam("uid") String uid) {
        Sret sr = us.addLocation(lon, lat, timestamp, uid);
        log.debug("/location/add, success");
        return sret2json(sr);
    }
    
//    //id降序列出所有公告
//    @RequestMapping("/notice/list")
//    public String do_listNotice() {
//        Sret sr = us.listNotice();
//        log.debug("/notice/list, success");
//        return sret2json(sr);
//    }
//    
//    //根据id查询对应的公告
//    @RequestMapping("/notice/search")
//    public String do_searchNotice(@RequestParam("id") String id) {
//        Sret sr = us.searchNotice(id);
//        log.debug("/notice/search, success");
//        return sret2json(sr);
//    }
    
    //根据uid查询所有用户订单及对应的评分、评价
    @RequestMapping("/package/query")
    public String do_queryEvaluation(@RequestParam("uid") String uid) {
        Sret sr = us.queryEvaluation(uid);
        log.debug("/package/query, success");
        return sret2json(sr);
    }
    
    //列出用户进行中的订单
    @RequestMapping("/ongoing/list")
    public String do_listOngoing(@RequestParam("uid") String uid) {
        Sret sr = us.listOngoing(uid);
        log.debug("/ongoing/list, success");
        return sret2json(sr);
    }
    
    //列出用户已完成的订单
    @RequestMapping("/completed/list")
    public String do_listCompleted(@RequestParam("uid") String uid) {
        Sret sr = us.listCompleted(uid);
        log.debug("/completed/list, success");
        return sret2json(sr);
    }
    
    //列出用户已取消的订单
    @RequestMapping("/canceled/list")
    public String do_listCanceled(@RequestParam("uid") String uid) {
        Sret sr = us.listCanceled(uid);
        log.debug("/canceled/list, success");
        return sret2json(sr);
    }

    private String sret2json(Sret sr) {
        return new Gson().toJson(sr);
    }
	
//    //登录验证
//    @RequestMapping("/app/loginPass")
//    public String do_LoginPass(@RequestParam("phone") String phone, @RequestParam("pwd") String pwd) {
//        Sret sr = us.LoginPass(phone, pwd);
//        log.debug("/app/loginPass, success");
//        return sret2json(sr);
//    }
//
//    //添加用户
//    @RequestMapping("/app/addUser")
//    public String do_addUser(@RequestParam("nickname") String nickname, @RequestParam("phone") String phone, @RequestParam("type") String type, @RequestParam("pwd") String pwd, @RequestParam("email") String email) {
//        Sret sr = us.addUser(nickname, phone, type, pwd, email);
//        return sret2json(sr);
//    }
//    
//    //获取车辆状态
//    @RequestMapping("/app/getStatus")
//    public String do_getStatus(@RequestParam("id") String id) {
//        Sret sr = us.getStatus(id);
//        log.debug("/app/getStatus, success");
//        return sret2json(sr);
//    }
//    
//    //修改个人资料
//    @RequestMapping("/app/alterInfo")
//    public String do_alterInfo(@RequestParam("nickname") String nickname, @RequestParam("email") String email, @RequestParam("phone") String phone, @RequestParam("id") String id) {
//        Sret sr = us.alterInfo(nickname, email, phone, id);
//        return sret2json(sr);
//    }
//	
//	//修改车辆状态
//    @RequestMapping("/app/alterStatus")
//    public String do_alterStatus(@RequestParam("status") String status, @RequestParam("id") String id) {
//        Sret sr = us.alterStatus(status, id);
//        return sret2json(sr);
//    }
//    
//    //获取订单
//    @RequestMapping("/app/getOrder")
//    public String do_getOrder(@RequestParam("user_id") String user_id, @RequestParam("priority") String priority) {
//        Sret sr = us.getOrder(user_id, priority);
//        log.debug("/app/getOrder, success");
//        return sret2json(sr);
//    }
}
